package com.agent.commons.Result;

import lombok.Data;

@Data
public class Result<T> {

    /**
     * 状态码
     */
    private Integer code;
    /**
     * 状态信息
     */
    private String message;
    /**
     * 传递数据
     */
    private T data;

    public static <T> Result<T> success(){
        Result<T> result=new Result<>();
        result.setCode(200);
        return result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result=new Result<>();
        result.setCode(200);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(Integer code,String message){
        Result<T> result=new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }


    public static <T> Result<T> error(String message){
        Result<T> result=new Result<>();
        result.message = message;
        result.code = 201;
        return result;
    }

    public static <T> Result<T> error(T data){
        Result<T> result=new Result<>();
        result.code = 201;
        result.data = data;
        return result;
    }


}
